package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.ReturnPlanInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.ReturnPlanInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.crm.jdy.service.client.ReturnPlanInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 回款计划表API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月26日
*
*/
@Validated
@Api(tags = "returnPlanInfo", description = "回款计划表")
@RestController
@RequestMapping("/returnPlanInfo")
public class ReturnPlanInfoController{

    @Reference(version = "${service.version}", check = false)
    ReturnPlanInfoService returnPlanInfoService;

    @RateLimit()
    @ApiOperation("回款计划表")
    @PostMapping("/seleteReturnPlanInfo")
    public ResultVo seleteReturnPlanInfo(@RequestBody ReturnPlanInfoDto callAplanInfoDto){
        callAplanInfoDto.setIplanStatus("0");
        PageInfo<ReturnPlanInfo> list = returnPlanInfoService.seleteReturnPlanInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新回款计划表")
    @PostMapping("/updatReturnPlanInfo")
    public ResultVo updatReturnPlanInfo(@ApiParam(value = "returnPlanInfo", required = true)
                                        @Validated @RequestBody ReturnPlanInfo returnPlanInfo){
        returnPlanInfo.setIplanStatus("0");
        boolean index = returnPlanInfoService.updateReturnPlanInfo(returnPlanInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加回款计划表")
    @PostMapping("/addReturnPlanInfo")
    public ResultVo addReturnPlanInfo(@ApiParam(name = "returnPlanInfo", required = false)
                                      @Validated @RequestBody ReturnPlanInfo returnPlanInfo){
        boolean list  = returnPlanInfoService.addReturnPlanInfo(returnPlanInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除回款计划表")
    @DeleteMapping("deleteReturnPlanInfo/{iplanId}")
    public ResultVo deleteReturnPlanInfo(@NotNull @ApiParam(name = "iplanId", value = "iplanId", required = true) @PathVariable String iplanId){
        boolean b = returnPlanInfoService.removeReturnPlanInfo(iplanId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("回款表")
    @PostMapping("/seleteReturnInfo")
    public ResultVo seleteReturnInfo(@RequestBody ReturnPlanInfoDto callAplanInfoDto){
        callAplanInfoDto.setIplanStatus("1");
        PageInfo<ReturnPlanInfo> list = returnPlanInfoService.seleteReturnPlanInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新回款表")
    @PostMapping("/updatReturnInfo")
    public ResultVo updatReturnInfo(@ApiParam(value = "returnPlanInfo", required = true)
                                        @Validated @RequestBody ReturnPlanInfo returnPlanInfo){
        returnPlanInfo.setIplanStatus("1");
        boolean index = returnPlanInfoService.updateReturnPlanInfo(returnPlanInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("回款表和计划表")
    @PostMapping("/seleteReturn")
    public ResultVo seleteReturn(@RequestBody ReturnPlanInfoDto callAplanInfoDto){
        PageInfo<ReturnPlanInfo> list = returnPlanInfoService.seleteReturnPlanInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

}